package model
{
	/**
	 * Model object representing the Project class.
	 *  
	 * @author linden
	 * 
	 */
	public class ProjectVO
	{
		static public var MAX_LEN_NAME:int = 200;
		
		public var id:int;
		private var _name:String;
		//this keeps track of either tasks or categories, depending on sorting
		[Bindable]
		public var children:Array = new Array();

		public function ProjectVO( name:String="", id:int=-1 )
		{
			this.name = name;
			this.id = id;
		}
		
		// Seperate setter and getter to enforce max length
		[Bindable]
		public function set name( value:String ):void
		{
			_name = value.slice(0, MAX_LEN_NAME);
		}
		
		public function get name():String
		{
			return _name;
		}

		public function get label():String
		{
			return _name;
		}
		
		[Bindable]
		public function get numTasks():int
		{
			var n:int = 0;
			for each ( var c:CategoryVO in children )
			{
				n += c.children.length;
			}
			return n;
		}
		
		[Bindable]
		public function get numFinishedTasks():int
		{
			var n:int = 0;
			for each ( var c:CategoryVO in children )
			{
				for each ( var t:TaskVO in c.children )
				{
					if (t.completed)
					{
						n += 1;
					}
				}
			}
			return n;
		}

	}
}